package com.example.administrator.myapplication;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;

import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity{

    @Bind(R.id.send_start)
    Button sendStart;
    @Bind(R.id.send_pause)
    Button sendPause;
    @Bind(R.id.send_stop)
    Button sendStop;
    @Bind(R.id.seek_bar)
    SeekBar seekBar;

    private ServiceConnection sc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        sc = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
                CustomService service1 = ((CustomService.MyBinder) service).getService();
                service1.getSeekBar(seekBar);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {

            }
        };

    }

    @Override
    protected void onStop() {
        super.onStop();
        unbindService(sc);
    }

    @OnClick({R.id.send_start, R.id.send_pause, R.id.send_stop})
    public void onViewClicked(View view) {
        Intent intentService = new Intent(this, CustomService.class);
        switch (view.getId()) {
            case R.id.send_start:
                intentService.setAction("STARTMUSICE");
                bindService(intentService,sc,BIND_AUTO_CREATE);
                break;
            case R.id.send_pause:
                intentService.setAction("PAUSEMUSICE");
                break;
            case R.id.send_stop:
                intentService.setAction("STOPMUSICE");
                break;
        }
        startService(intentService);
    }
}
